#include "skslineedit.h"

#include <QKeyEvent>
#include <QInputMethodEvent>
#include <QtDebug>
#include <QApplication>


SKSLineEdit::SKSLineEdit(QWidget *parent)
    : QLineEdit(parent)//, inputPanel(new MyInputPanel(this))
{
    //installEventFilter(inputPanel);
    //buildConnections();
}

SKSLineEdit::SKSLineEdit(const QString &contents, QWidget *parent)
    : QLineEdit(contents, parent)
{
    //installEventFilter(inputPanel);
    //buildConnections();
}

void SKSLineEdit::buildConnections()
{
    //connect(this, SIGNAL(keypressed(QKeyEvent*)), inputPanel, SLOT(handleQKeyEvent(QKeyEvent*)));
    //connect(inputPanel, SIGNAL(send_backspace()), this, SLOT(onSendBackspace()));
    //connect(inputPanel, SIGNAL(send_back(QEvent*)), this, SLOT(onSendBackEvent(QEvent*)));
    //connect(inputPanel, SIGNAL(send_preedit(const QString&)), this, SLOT(onSendPreedit(const QString&)));
    //connect(inputPanel, SIGNAL(send_commit(const QString&)), this, SLOT(onSendCommit(const QString&)));
}

bool SKSLineEdit::eventFilter(QObject *obj, QEvent *event)
{
    //if (event->type() == QEvent::KeyPress) {
    //    QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
    //    emit keypressed(keyEvent);

    //    return true;
    //} else {
        // pass the event on to the parent class
    //    return QLineEdit::eventFilter(obj, event);
    //}
}

void SKSLineEdit::onSendBackspace()
{
    //QKeyEvent* evt = new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
    //inputPanel->setVisible(false);
    //QLineEdit::event(evt);
}

void SKSLineEdit::onSendBackEvent(QEvent* evt)
{
    //QLineEdit::event(evt);
}

void SKSLineEdit::onSendCommit(const QString& text)
{
    //QInputMethodEvent *event = new QInputMethodEvent;
    //event->setCommitString(text);
    //qApp->postEvent(this, event);
}

void SKSLineEdit::onSendPreedit(const QString& text)
{
    //QInputMethodEvent *event =
    //        new QInputMethodEvent(text, QList<QInputMethodEvent::Attribute>());

    //qApp->postEvent(this, event);
}
